package com.j4dream.webapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.j4dream.dbentity.DailyVolumeDBVO;
import com.j4dream.domain.DailyVolumeDomain;
import com.j4dream.domain.factory.DomainFactoryService;
import com.j4dream.repository.DailyVolumeAutoRepo;
import com.j4dream.repository.DailyVolumeRepo;
import com.j4dream.webapp.model.DailyVolumeModel;
import com.j4dream.webapp.model.common.ResponseModel;

@Controller
public class DailyVolumeController {

	@Autowired
	private DomainFactoryService domainFactoryService;
	@Autowired
	private DailyVolumeAutoRepo dailyVolumeAutoRepo;
	@Autowired
	private DailyVolumeRepo dailyVolumeRepo;

	@ResponseBody
	@RequestMapping(value = "/lists/dailyVolumes", method = RequestMethod.POST)
	public ResponseModel create(@RequestBody DailyVolumeModel model) {
		ResponseModel responseModel = new ResponseModel();

		DailyVolumeDomain dailyVolumeDomain = domainFactoryService.buildDailyVolume(new DailyVolumeDBVO(model.getDomains(), model.getVolume(), "1"));
		dailyVolumeDomain.createInDB();

		DailyVolumeModel dailyVolumeModel = new DailyVolumeModel(dailyVolumeDomain.getData().getId(), dailyVolumeDomain.getData().getDomain(),
				dailyVolumeDomain.getData().getVolume());
		responseModel.setData(dailyVolumeModel);
		responseModel.setMessage("success!");
		return responseModel;
	}

}
